package com.ys.dto;

import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * 编辑数据返回后续操作
 * @author Jason
 *
 */
@Data
@AllArgsConstructor
public class EditDto {
	private Integer code;
	private Long id;
	private String url;
	
    public enum Code {
    	
    	NO_ACTION("无动作", 0),
		CLODE_AND_RELOAD("关闭当前页并刷新父列表", 2),
		RELOAD_PAGE("刷新页面", 3),
		CLODE_TAB("关闭当前标签页", 4),
		OPEN_NEW_PAGE("跳转新页面", 5);
    	public String name;
    	public Integer value;

    	private Code(String name, Integer value) {
    		this.name = name;
    		this.value = value;
    	}

    	public static String getName(int value) {
    		for (Code e : Code.values()) {
    			if (e.value == value) {
    				return e.name;
    			}
    		}

    		return "";
    	}
    }
    
    public static EditDto noAction() {
    	return new EditDto(Code.NO_ACTION.value, null, null);
    }
    
    public static EditDto reloadPage(String url) {
    	return new EditDto(Code.RELOAD_PAGE.value, null, url);
    }
    
    public static EditDto closeAndReload() {
    	return new EditDto(Code.CLODE_AND_RELOAD.value, null, null);
    }
    
    public static EditDto closeTab() {
    	return new EditDto(Code.CLODE_TAB.value, null, null);
    }

	public static EditDto openNewPage(String url) {
		return new EditDto(Code.OPEN_NEW_PAGE.value, null, url);
	}
}